import {
  getRoleList,
  addOneRole,
  updateOneRole,
  getRoleByID,
  deleteOneRole
} from '@/api/role'

const role = {
  state: {
  },

  mutations: {
  },

  actions: {
    // 获取角色列表
    getRoleList({ commit }, condition) {
      return new Promise((resolve, reject) => {
        getRoleList(condition).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 新增一个角色
    addOneRole({ commit }, data) {
      return new Promise((resolve, reject) => {
        addOneRole(data).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 根据id查询角色详情
    getRoleByID({ commit }, id) {
      return new Promise((resolve, reject) => {
        getRoleByID(id).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 更新一个角色
    updateOneRole({ commit }, data) {
      return new Promise((resolve, reject) => {
        updateOneRole(data).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 删除一个角色
    deleteOneRole({ commit }, data) {
      return new Promise((resolve, reject) => {
        deleteOneRole(data).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    }
  }
}

export default role
